package com.xbfinal.eduservice.controller;


import com.xbfinal.commonUtils.Result;
import com.xbfinal.eduservice.entity.subject.OneSubject;
import com.xbfinal.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 * @author xbfinal
 * @since 2023-01-05
 */
@Api("课程分类管理")
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;
    /**
     * 添加课程分类
     * 获取上传的文件，把文件内容读出来
     */

    @ApiOperation("添加课程")
    @PostMapping("addSubject")
    public Result addSubject(MultipartFile file){
        // 1.得到上传的文件 MultipartFile file
        return eduSubjectService.saveSubject(file,eduSubjectService);
    }


    /**
     * 课程分类列表
     * 对应实体类 subject
     * @return
     */
    @ApiOperation("课程分类列表")
    @GetMapping("/getAllSubject")
    public Result getAllSubject(){


        //        方法查询返回了 一级和二级分类
        List<OneSubject>list = eduSubjectService.getAllOneAndTwoSub();
        return Result.ok().addData(list);
    }

}

